📦 Scalars, Vectors, and Matrices
Welcome to the foundational building blocks of all Machine Learning data! Don't let the math terms scare you—think of these simply as different types of containers for our data.
1. 🟢 Scalars (The Single Value)
A Scalar is just a fancy word for a single, standalone number.
- Analogy: Imagine a single temperature reading on a thermometer:
72°F. That's a scalar.
2. 📏 Vectors (The List)
A Vector is a 1D list of scalars.
- Analogy: Think of a shopping list.
[Apples, Bananas, Milk]translates to[2, 5, 1]in numbers.
3. 🍱 Matrices (The Spreadsheet)
A Matrix is a 2D grid of numbers—essentially a list of vectors.
- Analogy: Think of an Excel spreadsheet. Each row is a house, and each column is a feature (size, beds, baths).
🐍 Python Implementation
In Python, we use the numpy library to handle all of this effortlessly!
import numpy as np
# Scalar (0D Tensor)
temperature = np.array(72)
print("Scalar:", temperature)
# Vector (1D Tensor) - e.g., A house with 2 beds, 1 bath, 1500 sqft
house_features = np.array([2, 1, 1500])
print("Vector:\n", house_features)
# Matrix (2D Tensor) - e.g., 3 houses
dataset = np.array([
[2, 1, 1500],
[3, 2, 2000],
[1, 1, 900]
])
print("Matrix:\n", dataset)